<?php


/**
 * Notes:
 * PROJECT_NAME : ERP v1.8 重构erp
 * User: 夏鱼儿<397072174@qq.com>
 * Date: 2024/3/25
 * Time: 10:32
 */

namespace app\service\base;

use app\service\traits\model\GetAttr;
use app\service\traits\model\Line;
use app\service\traits\model\SearchAttr;
use think\model\concern\SoftDelete;

/**
 * @method status($status) 自定义方法
 * @method type($type) 自定义方法
 * @method static gs($company_id = 0) 自定义方法 查找公司
 * @method static goodsRuleId($goodsRuleId) 自定义方法 查找规格
 * @method static goodsId($goodsId) 自定义方法 查找商品
 * @method static supplierId($supplierId) 自定义方法 查找经销商
 * @method static orderStatus() 自定义方法 查找规格
 * @method static warehouseId($warehouseId) 自定义方法 查找仓库
 * @method static storeId($storeID) 自定义方法 查找门店
 * @method seekGoods($company_id, $goods_id)
 */
class Model extends \think\Model
{

    // 定义时间戳字段名
    protected $createTime = 'create_time';

    protected $updateTime = 'update_time';

    // 软删除
    use SoftDelete;

    protected string $deleteTime        = 'delete_time';
    protected        $defaultSoftDelete = 0;

    use GetAttr;
    use SearchAttr;
    use Line;


    /**
     * @param $query
     * @param int $status
     */
    public function scopeStatus($query, int $status = 1)
    {
        $query->where('status', $status);
    }

    /**
     * @param $query
     * @param int $order_status
     */
    public function scopeOrderStatus($query, int $order_status = 1)
    {
        $query->where('order_status', $order_status);
    }

    /**
     * @param $query
     * @param int $type
     */
    public function scopeType($query, int $type = 1)
    {
        $query->where('type', $type);
    }

    /**
     * @param $query
     * @param int $company_id
     * @return void
     */
    public function scopeGs($query, int $company_id = 0): void
    {
        if (!$company_id) {
            $company_id = getCompanyId(app('http')->getName());
        }
        $query->where('company_id', $company_id);
    }

    /**
     * @param $query
     * @param $goodsRuleId
     * @return mixed
     */
    public function scopeGoodsRuleId($query, $goodsRuleId): mixed
    {
        return $query->where('goods_rule_id', $goodsRuleId);
    }

    public function scopeGoodsId($query, $goodsId)
    {
        if ($goodsId) $query->where('goods_id', $goodsId);
    }

    public function scopeStoreId($query, $storeId)
    {
        if ($storeId) $query->where('store_id', $storeId);
    }

    public function scopeSupplierId($query, $supplierId)
    {
        if ($supplierId) $query->where('supplier_id', $supplierId);
    }

    public function scopeWarehouseId($query, $warehouseId)
    {
        if ($warehouseId) $query->where('warehouse_id', $warehouseId);
    }

    public function scopeSeekGoods($query, $company_id, $goods_id)
    {
        $query->where('company_id', $company_id)->where('goods_id', $goods_id);
    }


}